'use strict';

/* Controllers */
  // signin controller
app.controller('useLogController', ['$scope', '$http', '$state', '$modal', 'user_info', 'toaster', function($scope, $http, $state, $modal, user_info, toaster) {
    $scope.loading = true;
    $scope.currentPage = 1;
    $scope.list = null;
    $scope.totalItem = 0;
    $scope.getPage = function(){
        $scope.loading = true;
        $http.get('/app/api/user/use/log/' + $scope.currentPage)
            .then(function(response) {
                $scope.loading = false;
                let result = response.data.data;
                $scope.list = result.list;
                $scope.totalItem = result.totalItem;
            }, function(x) {

            });
    };
    user_info.check($scope).then(function(){
        $scope.getPage();
    });
    $scope.addCache = function (index, id) {
        $http.get('/app/api/user/cache/add/' + id)
            .then(function (response) {
                toaster.pop("success", "添加缓存成功");
                $scope.list[index] = response.data.data;
            }, function (x) {
                toaster.pop("error", "添加缓存失败", x.data.message);
            });
    }
}]);